package app.Disthanitian.thaistyle.EmerMez;

import static app.Disthanitian.thaistyle.EmerMez.Constant.TABLE_NAME;
import static android.provider.BaseColumns._ID;
import static app.Disthanitian.thaistyle.EmerMez.Constant.ID;
import static app.Disthanitian.thaistyle.EmerMez.Constant.NAME;
import static app.Disthanitian.thaistyle.EmerMez.Constant.ORIGINLAT;
import static app.Disthanitian.thaistyle.EmerMez.Constant.ORIGINLNG;
import static app.Disthanitian.thaistyle.EmerMez.Constant.DESTINATIONLAT;
import static app.Disthanitian.thaistyle.EmerMez.Constant.DESTINATIONLNG;
import static app.Disthanitian.thaistyle.EmerMez.Constant.TIMES;
import static app.Disthanitian.thaistyle.EmerMez.Constant.TYPE;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseConnection extends SQLiteOpenHelper {

	private static final String DATABASE_NAME = "RiskZone33.db";
	private static final int DATABASE_VERSION = 1;

	public DatabaseConnection(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		db.execSQL("CREATE TABLE " + TABLE_NAME
				+ " (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + NAME
				+ " TEXT, " + ORIGINLAT + " TEXT, " + ORIGINLNG + " TEXT, "
				+ DESTINATIONLAT + " TEXT, " + DESTINATIONLNG + " TEXT, "
				+ TYPE + " TEXT, " + TIMES + " INTEGER);");
		db.execSQL("INSERT INTO "
				+ TABLE_NAME
				+ " ("
				+ NAME
				+ ", "
				+ ORIGINLAT
				+ ", "
				+ ORIGINLNG
				+ ", "
				+ DESTINATIONLAT
				+ ", "
				+ DESTINATIONLNG
				+ ", "
				+ TYPE
				+ ", "
				+ TIMES
				+ ") VALUES ('Test','13.64550461271','100.595377050','13.640117239831','100.5907633155','C',15);");
		db.execSQL("INSERT INTO "
				+ TABLE_NAME
				+ " ("
				+ NAME
				+ ", "
				+ ORIGINLAT
				+ ", "
				+ ORIGINLNG
				+ ", "
				+ DESTINATIONLAT
				+ ", "
				+ DESTINATIONLNG
				+ ", "
				+ TYPE
				+ ", "
				+ TIMES
				+ ") VALUES ('Test2','13.687140112679154','100.53525868803263','13.683660045847258','100.53900808095932','C',15);");
		db.execSQL("INSERT INTO "
				+ TABLE_NAME
				+ " ("
				+ NAME
				+ ", "
				+ ORIGINLAT
				+ ", "
				+ ORIGINLNG
				+ ", "
				+ DESTINATIONLAT
				+ ", "
				+ DESTINATIONLNG
				+ ", "
				+ TYPE
				+ ", "
				+ TIMES
				+ ") VALUES ('Test3','13.806831','100.631673','13.805372','100.632437','C',15);");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
		// TODO Auto-generated method stub
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
		onCreate(db);
	}

}
